package thread;

import java.io.*;
import java.net.*;

import workflow.ScraperManager;

public class ScrapeThread extends Thread {
	
	ScraperManager caller = null;
	String article = null;
	String poster = null;
	String host = "http://kazoolist.com/wwgha/searchCommentsByPoster.php?c=";
	
	public ScrapeThread(ScraperManager caller, String article, String poster){
		this.caller = caller;
		this.article = article;
		this.poster = poster;
	}
	
	public void run(){
		try{
			String address = host+URLEncoder.encode(poster)+"&u="
					+"http://whywontgodhealamputees.com/blog/?p="+article+"%23comments";
			URL url = new URL(address);
			BufferedReader br = new BufferedReader(
					new InputStreamReader(url.openStream()));
			StringBuffer sb = new StringBuffer();
			String s;
			while((s = br.readLine())!=null){
				sb.append(s);
			}
			caller.callBack("<p>++++ http://whywontgodhealamputees.com/blog/?p="+article+"</p>"
				+sb.toString());
		}catch(Exception e){
			caller.callBackException(e);
		}
	}

}
